<?php

use yii\helpers\Html;
use yii\widgets\ActiveForm;
use kartik\select2\Select2;
use yii\helpers\ArrayHelper;
use yii\widgets\Pjax;
use yii\grid\GridView;
use kartik\export\ExportMenu;

/* @var $this yii\web\View */
/* @var $searchModel app\models\CourseSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = '课程';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="course-index">

    <?php // echo $this->render('_search', ['model' => $searchModel]);  ?>

    <div class="col-md-12" style="margin-bottom: 12px">      
        <?php
        $form = ActiveForm::begin([
                    'action' => ['index'],
                    'method' => 'get',
                    'options' => ['class' => 'input-group'],
                    'fieldConfig' => [
                        'template' => '<div class="col-lg-12">{input}</div>',
                    ]
                ])
        ?>

        <div class="col-md-4">
            <label style="float: left;margin-top: 5px;">课程名称</label>
            <div style="overflow: hidden;">
                <?php
//                $data = app\models\Course::find()->all();
//                echo $form->field($searchModel, 'coursename')->widget(Select2::classname(), [
//                    'data' => ArrayHelper::map($data, 'coursename', 'coursename'),
//                    'options' => ['placeholder' => '请输入内容'],
//                    'pluginOptions' => [
//                        'allowClear' => true
//                    ],
//                ]);
                ?>       
                <?php
                $datas = app\models\Course::find()->all();
                if ($datas != null) {
                    foreach ($datas as $item) {
                        $source[] = $item->coursename;
                    }
                } else {
                    $source[] = array();
                }
                echo yii\jui\AutoComplete::widget([
                    'model' => $searchModel,
                    'attribute' => 'coursename',
                    'options'=>['style'=>'margin-left:10px'],
                    'clientOptions' => [
                        'source' => $source,
                    ],
                ]);
                ?>
            </div>
        </div>
        <div class="col-md-4">
            <label style="float: left;margin-top: 5px;">课程编号</label>
            <div style="overflow: hidden;">
                <?php
//                $data = app\models\Course::find()->all();
//                echo $form->field($searchModel, 'courseno')->widget(Select2::classname(), [
//                    'data' => ArrayHelper::map($data, 'courseno', 'courseno'),
//                    'options' => ['placeholder' => '请输入内容'],
//                    'pluginOptions' => [
//                        'allowClear' => true
//                    ],
//                ]);
                ?> 
                <?php
                if ($datas != null) {
                    foreach ($datas as $item) {
                        $source[] = $item->courseno;
                    }
                } else {
                    $source[] = array();
                }
                echo yii\jui\AutoComplete::widget([
                    'model' => $searchModel,
                    'attribute' => 'courseno',
                    'options'=>['style'=>'margin-left:10px'],
                    'clientOptions' => [
                        'source' => $source,
                    ],
                ]);
                ?>
            </div>
        </div>

        <div class="col-md-3" style="padding: 0px;margin: 0px">
            <label style="float: left;margin-top: 5px;">教师</label>
            <div style="overflow: hidden;">
                <?php
//                $data = app\models\Course::find()->all();
//                echo $form->field($searchModel, 'teacher')->widget(Select2::classname(), [
//                    'data' => ArrayHelper::map($data, 'teacher', 'teacher'),
//                    'options' => ['placeholder' => '请输入内容'],
//                    'pluginOptions' => [
//                        'allowClear' => true
//                    ],
//                ]);
                ?>   
                <?php
                if ($datas != null) {
                    foreach ($datas as $item) {
                        $source[] = $item->teacher;
                    }
                } else {
                    $source[] = array();
                }
                echo yii\jui\AutoComplete::widget([
                    'model' => $searchModel,
                    'attribute' => 'teacher',
                    'options'=>['style'=>'margin-left:10px'],
                    'clientOptions' => [
                        'source' => $source,
                    ],
                ]);
                ?>
            </div>
        </div>

        <div class="col-md-1 text-center">
            <?= Html::submitButton(' 搜索', ['class' => 'btn btn-primary glyphicon glyphicon-search']) ?> 
        </div>

    </div>

    <div class="col-md-5 text-right" style="margin: 10px 0 15px 15px;float: right;padding-right: 0">

        <?= Html::a('新增', ['create'], ['class' => 'btn btn-primary']) ?> 
        <button class="btn btn-success glyphicon glyphicon-print" onclick="printme()"> 打印</button>
        <span>&nbsp;&nbsp;</span>
        <?Php
        echo ExportMenu::widget([
            'dataProvider' => $dataProvider,
            'exportConfig' => [
                ExportMenu::FORMAT_TEXT => false,
                ExportMenu::FORMAT_PDF => false,
                ExportMenu::FORMAT_CSV => false,
                ExportMenu::FORMAT_EXCEL_X => false,
                ExportMenu::FORMAT_HTML => false
            ],
            'columns' => [
                ['class' => 'yii\grid\SerialColumn'],
                'id',
                'term',
                'courseno',
                'coursename',
                'creadit',
                'grade',
                'allperiod',
                'profession',
                'classtype1',
                'classtype2',
                'classes',
                'checktype',
                'studentnum',
                'teachperiod',
                'testperiod',
                'machineperiod',
                'otherperiod',
                'weekperiod',
                'teachweek',
                'examineweek',
                'teacher',
                'siterequirement',
                'arrangerequirement',
                'mark',
                'updatetime',
                'isfinish',
                'addman',
                'addmanid',
                'addtime',
                'mon',
                'tue',
                'wed',
                'thu',
                'fri',
                'regmatch:ntext',
                'term',
            ]
        ]);
        ?>
    </div>

    <?php ActiveForm::end(); ?>    
    <?php Pjax::begin(); ?>
    <?=
    GridView::widget([
        'id' => 'tableContainer',
        'tableOptions' => ['class' => 'table table-bordered'],
        'rowOptions' => [
            'style' => '
                        border-bottom: 18px solid #EFEFEF;
                        white-space: nowrap;
                        overflow: hidden;
                        text-overflow: ellipsis;
                        height: 50px;
                        '],
        'headerRowOptions' => [
            'style' => 'font-size: 15px;color: #2a70e9;background-color: #D9EDF7;',
        ],
        'layout' => "{items}\n{pager}",
        'dataProvider' => $dataProvider,
        'columns' => [
            // ['class' => 'yii\grid\SerialColumn'],
            //'id',
//               'coursename',
             [
                'attribute' => 'coursename',
                'label' => '课程名称',
                'format' => 'raw',               
                'value'=>function ($model) {
                      return Html::a($model->coursename,['course/view','id'=>$model->id]);
                      },
                'contentOptions' => ['style' => ''],
                'headerOptions' => ['style' => ''],
            ],
             'courseno',
            'term',
            'creadit',
            'grade',
            // 'allperiod',
            // 'profession',
            // 'classtype1',
            // 'classtype2',
            // 'classes',
            // 'checktype',
            // 'studentnum',
            // 'teachperiod',
            // 'testperiod',
            // 'machineperiod',
            // 'otherperiod',
            // 'weekperiod',
            // 'teachweek',
            // 'examineweek',
            // 'teacher',
            // 'siterequirement',
            // 'arrangerequirement',
            // 'mark',
            // 'updatetime',
            // 'isfinish',
            // 'addman',
            // 'addmanid',
            // 'addtime',
            // 'mon',
            // 'tue',
            // 'wed',
            // 'thu',
            // 'fri',
            // 'regmatch:ntext',
            'term',
            [
                'class' => 'yii\grid\ActionColumn',
                'template' => '{update} {delete}',
                'buttons' => [
                    //update button
                    'update' => function ($url) {
                        return Html::a('<span class="fa fa-search"></span>编辑', $url, [
                                    'title' => Yii::t('app', 'Update'),
                                        // 'class' => 'btn btn-primary btn-md',
                        ]);
                    },
                            //update button
                            'delete' => function ($url) {
                        return Html::a('<span class="fa fa-search"></span>删除', $url, [
                                    'title' => Yii::t('app', 'Delete'),
                                    'data-confirm' => Yii::t('yii', 'Are you sure you want to delete this item?'),
                                    'data-method' => 'post',
                                    'data-pjax' => '0',
                                        //  'class' => 'btn btn-primary btn-md',
                        ]);
                    },
                        ],
                    ],
                ],
            ]);
            ?>
            <?php Pjax::end(); ?>
</div>
<script>
    var global_Html = "";
    function printme() {
        global_Html = document.body.innerHTML;
        document.body.innerHTML = $('#tableContainer').html();
        $('.btn').hide();
        $('.pagination').hide();
        $('a').each(function () {
            $(this).replaceWith($(this).html());
        });
        window.print();
        window.setTimeout(function () {
            document.body.innerHTML = global_Html;
        }, 300);
    }

</script>